﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace iMKelly {
    using CoreClass;
    public delegate void CompleteHandler();
    public partial class frmImport : Form {
        CoreClass.Database dbs;
        public event CompleteHandler Complete;
        private bool isImportMode = true;
        public frmImport() {
            InitializeComponent();
        }
        public frmImport(CoreClass.Database dbs) {
            InitializeComponent();
            this.dbs = dbs;
            id.Text = dbs.getNextBookTitleID();
            isImportMode = true;
        }

        public frmImport(CoreClass.Database dbs, BookTitle title) {
            InitializeComponent();
            this.dbs = dbs;
            id.Text = title.TitleID;
            name.Text = title.Name;
            author.Text = title.Author;
            pulisher.Text = title.Publisher;
            amount.Text = title.Amount.ToString();
            isImportMode = false;
        }

        private void import_Click(object sender, EventArgs e) {
            BookTitle title = new BookTitle(id.Text, name.Text, author.Text, pulisher.Text, Convert.ToInt16(amount.Text));
            if (isImportMode) dbs.importBook(title);
            else dbs.updateBookTitle(title.TitleID, title);
            Complete();
            this.Dispose();
        }

        private void cancel_Click(object sender, EventArgs e) {
            this.Dispose();
        }

    }
}
